<?php

namespace IDock\Insurance\TPIC\Request;

use IDock\Insurance\TPIC\Request\AllTPICRequest;
use IDock\Insurance\TPIC\Response\UploadFileResponse;
use IDock\Insurance\TPIC\Response\VehicleModelResponse;
use IDock\Insurance\TPIC\TPICEnums;
use IDock\Visitor\UploadFileVisitor;
use IDock\Visitor\VehicleModelVisitor;

/**
 * 图片上传
 */
class UploadFileRequest extends AllTPICRequest
{
    protected $response = UploadFileResponse::class;

    protected $urlTip = '影像资料上传';

//    protected $inLog = false;

    public $route = 'uploadImg';

    /**
     * @var UploadFileVisitor $visitor
     */
    protected $visitor;

    public function generate(): array
    {
        $row = $this->visitor->getFileList()[0] ?? [];
        $fixArr = explode('.',$row['url'] ?? '');
        $fix = end($fixArr);
        if(!in_array($fix,['jpg','png','jpeg'])){
            throw new \Exception("不支持$fix 的图片格式");
        }
        return [
            'imageInfo' => [
                'imageType' => TPICEnums::$uploadImageType[$row['type'] ?? ''] ?? '',
                'imageSuffix' => $fix,
                'imageBase64' => base64_encode(file_get_contents($row['url']))
            ],
            'order' => [
                'orderNo' => $this->visitor->argc['orderNo'] ?? '',
            ]
        ];
    }
}
